package org.example.auth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthController {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 判断指定的token是否为认证状态
     * @param token 认证token
     * @return 是否认证
     */
    @GetMapping("/auth/hasAuth")
    public Boolean hasAuth(@RequestParam String token) {
        String authPrefix = "auth_";
        return redisTemplate.hasKey(authPrefix + token);
    }
}
